package com.me.customerdemo.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.me.customerdemo.dao.SalesPlanMapper;
import com.me.customerdemo.pojo.SalesChannces;
import com.me.customerdemo.pojo.SalesPlan;
import com.me.customerdemo.service.SalesPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SalesPlanServerImpl implements SalesPlanService {

    @Autowired
    private SalesPlanMapper salesPlanMapper;

    @Override
    public List<SalesPlan> selectAll() {
        return salesPlanMapper.selectAll();
    }

    @Override
    public SalesPlan findById(int id) {
        return salesPlanMapper.selectById(id);
    }

    @Override
    public boolean updateById(SalesPlan salesPlan) {
        return salesPlanMapper.updateById(salesPlan)>0? true:false;
    }

    @Override
    public boolean deleteById(int id) {
        return salesPlanMapper.deleteById(id)>0?true:false;
    }

    @Override
    public boolean apply(SalesPlan salesPlan) {
        return salesPlanMapper.apply(salesPlan)>0?true:false;
    }

    @Override
    public PageInfo<SalesPlan> findByKeyword(int pageNum, int pageSize, String keyword) {
        PageHelper.startPage(pageNum,pageSize);
        List<SalesPlan> productTypes = salesPlanMapper.selectByKeyword(keyword);
        PageInfo<SalesPlan> page = new PageInfo<>(productTypes);
        return page;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean modify(SalesPlan salesPlan) {
        return salesPlanMapper.updateById(salesPlan) > 0;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean removeById(int id) {
        return salesPlanMapper.deleteById(id) > 0;
    }
}
